home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / prtln.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  4.0 KB  |  148 lines

  1. ;void  prtln(strg,printer_codes);
  2. ;  char  *strg,*printer_codes;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.     EXTRN  _time_out:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME  CS:_TEXT
  10.     PUBLIC  _prtln
  11. _prtln    proc near
  12.     jmp  short start    ;jump over local data
  13. delay    dw   ?            ;
  14. target    dw   ?            ;
  15. start:    push bp            ;
  16.     mov  bp,sp        ;
  17.     push di            ;
  18.     push si            ;
  19.     cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    mov  ah,1        ;BIOS func to init prtr
  24.     sub  dx,dx        ;choose LPT1
  25.     int  17h        ;initialize the prtr port
  26.     sub  ax,ax        ;clear AX
  27.     mov  es,ax        ;point ES to 0000:0000
  28.     mov  dx,es:[408h]    ;get LPT1 base address
  29.     push ds            ;save Turbo's DS
  30.     cmp  _memory_model,2    ;data near or far?
  31.     jb   A0            ;jump if near
  32.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg        
  33.     les  di,dword ptr[bp+8]    ;ES:DI pts to printer codes
  34.     jmp  short A00        ;
  35. A0:    mov  si,[bp+4]        ;NEAR case
  36.     push ds            ;
  37.     pop  es            ;
  38.     mov  di,[bp+6]        ;
  39. A00:    mov  _error_code,1    ;1 = printer error
  40.     mov  al,_time_out    ;get _time_out seconds
  41.     or   al,al        ;don't allow zero
  42.     jnz  A1            ;
  43.     mov  al,3        ;default to 3 seconds
  44. A1:    mov  cl,18        ;18 ticks per second
  45.     mul  cl            ;
  46.     mov  cs:delay,ax    ;save delay
  47.     sub  cx,cx        ;clear CX
  48.     cmp  byte ptr[si],0    ;null string?
  49.     je   H1            ;quit if null
  50. B1:    mov  al,[si]        ;get a character
  51.     inc  si            ;forward Strg ptr for next time
  52.     cmp  al,0        ;end of string?
  53.     je   LX            ;
  54.     cmp  al,128        ;test if control code
  55.     jb   F1            ;jump if below range
  56.     cmp  al,159        ;test if above
  57.     ja   F1            ;jump if above
  58.     push cx            ;save Strg len ctr
  59.     push di            ;save array ptr
  60.     sub  al,128        ;count codes from 0
  61.     mov  cl,6        ;times six bytes
  62.     mul  cl            ;offset in PrinterCodes
  63.     add  di,ax        ;now ES:DI pts to code sequence
  64.     sub  cx,cx        ;clear CX
  65.     mov  cl,es:[di]        ;get string descriptor
  66.     jcxz E1            ;quit loop if null
  67. C1:    inc  di            ;forward ptr
  68.     mov  al,es:[di]        ;get code character
  69.     call Writeit        ;write the code
  70.     or   ah,ah        ;printer error?
  71.     jnz  D1            ;continue if not
  72.     add  bp,4        ;balance stack
  73.     jmp  short H1        ;quit routine
  74. D1:    loop C1            ;go do next
  75. E1:    pop  di            ;restore array ptr
  76.     pop  cx            ;restore Strg len ctr
  77.     jmp  short G1        ;go get next char in Strg
  78. F1:    call Writeit        ;go write character
  79.     or   ah,ah        ;proc returned error?
  80.     jz   H1            ;quit if so
  81. G1:    jmp  short B1        ;loop
  82. LX:    mov  al,13        ;CR
  83.     call Writeit        ;print it
  84.     or   ah,ah        ;test for error
  85.     jz   H1            ;quit if error
  86.     mov  al,10        ;LF
  87.     call Writeit        ;print it
  88.     or   ah,ah        ;test for error
  89.     jz   H1            ;quit if error
  90.     pop  ds            ;
  91.     dec  _error_code    ;0 = all OK
  92.     jmp  short I1        ;
  93. H1:    pop  ds            ;
  94. I1:    pop  si            ;
  95.     pop  di            ;
  96.     pop  bp            ;
  97.     cmp  _memory_model,0    ;quit
  98.     jle  quit        ;
  99.     db   0CBh        ;RET far
  100. quit:    ret            ;RET near
  101. _prtln    endp
  102. Writeit    PROC
  103.     out  dx,al        ;send to output data register
  104.     inc  dx            ;forward to status register
  105.     push cx            ;save string counter
  106.     call GetBiosCount    ;get timer reading
  107.     mov  bx,cx        ;make copy
  108.     add  cx,cs:delay    ;add delay count
  109.     cmp  bx,cx        ;if timer doesn't turn over...
  110.     jb   J1            ;go ahead
  111.     mov  cx,cs:delay    ;otherwise, extend delay
  112. J1:    mov  cs:target,cx    ;save target count
  113. Wait:    in   al,dx        ;get status value
  114.     test al,8        ;test for printer error
  115.     jz   Error        ;
  116.     test al,80h        ;test for Printer Ready
  117.     jnz  Ready        ;jump if ready
  118. Error:    call GetBiosCount    ;
  119.     cmp  cx,cs:target    ;compare to target count
  120.     jb   Wait        ;    
  121.     mov  bl,1        ;1 = error
  122.     pop  cx            ;restore string counter
  123.     mov  ah,0        ;return code for failure
  124.     jmp  short K1        ;return
  125. Ready:    pop  cx            ;restore string counter
  126.     inc  dx            ; output control register
  127.     mov  al,13        ;bits for strobe signal
  128.     out  dx,al        ;send the signal
  129.     dec  al            ;change to strobe OFF
  130.     out  dx,al        ;send the signal
  131.     dec  dx            ;point back to
  132.     dec  dx            ;  base address
  133.     mov  ah,1        ;return code for success
  134. K1:    ret              ;
  135. Writeit    endp
  136. GetBIOSCount PROC
  137.     push dx            ;return value in CX:DX
  138.     push ax            ;
  139.     sub  ah,ah        ;function number
  140.     int  1ah        ;get timer count
  141.     mov  cx,dx        ;low word in CX
  142.     pop  ax            ;
  143.     pop  dx
  144.     ret
  145. GetBIOSCount endp
  146. _TEXT    ENDS
  147.     END
  148.